package com.example.meituan.activity.user.adapter;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.example.meituan.R;
import com.example.meituan.activity.bean.TypeBean;
import com.example.meituan.activity.user.onItemClick;

import java.util.List;

public class typeAdapter extends RecyclerView.Adapter<typeAdapter.TypeViewHolder>{
    private static onItemClick listener;
    private List<TypeBean> typeList;
    public typeAdapter(List<TypeBean> typeList,onItemClick listener) {
        this.typeList = typeList;
        this.listener=listener;
    }


    @NonNull
    @Override
    public typeAdapter.TypeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_list, parent, false);
        return new typeAdapter.TypeViewHolder(view);
    }

    @Override
    public int getItemCount() {
        return typeList.size();
    }

    @Override
    public void onBindViewHolder(@NonNull typeAdapter.TypeViewHolder holder, int position) {
        TypeBean type = typeList.get(position);
        holder.bind(type);
    }
    public static class TypeViewHolder extends RecyclerView.ViewHolder {
        TextView typeName;
        LinearLayout linearLayout;
        public TypeViewHolder(@NonNull View itemView) {
            super(itemView);
           typeName=itemView.findViewById(R.id.shop_car_type);

        }

        public void bind(TypeBean type) {
            typeName.setText(type.getTypeDescription());
            itemView.setOnClickListener(v -> {
                if (listener != null) {
                    listener.onItemClick(type);
                }
            });
        }
    }

}
